package com.xiaoxi.decoratormode.border;

import com.xiaoxi.decoratormode.display.Display;

/**
 * @Author xiaoxi
 * @ProjectName design_mode
 * @PackageName com.xiaoxi.decoratormode.border
 * @ClassName SurroundBorder
 * @Description TODO
 * @Date 2023/3/14 17:10
 * @Version 1.0
 */
public class SurroundBorder extends Border {

    private char ch;

    public SurroundBorder(Display display, char ch) {
        super(display);
        this.ch = ch;
    }

    @Override
    public String getRowText(int row) {
        if (row > getRows()) {
            return "";
        }
        StringBuilder sb = new StringBuilder();
        if (row == 0) {
            for (int i = 0; i < display.getColumns() + 2; i++) {
                sb.append(ch);
            }
            sb.append("\n");
        }
        sb.append(ch).append(display.getRowText(row)).append(ch);
        if (row == getRows() - 1) {
            sb.append("\n");
            for (int i = 0; i < display.getColumns() + 2; i++) {
                sb.append(ch);
            }
        }
        return sb.toString();
    }
}
